package com.zhuiyun.educations.api.teacher.controller;

import com.zhuiyun.educations.api.rotationimage.entity.ImageFile;
import com.zhuiyun.educations.api.teacher.entity.Teacher;
import com.zhuiyun.educations.api.teacher.service.TeacherService;
import com.zhuiyun.educations.common.response.CommonResult;
import com.zhuiyun.educations.util.pageUtil.PageRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName TeacherController
 * @Description TODO 教师信息控制层
 * @Author 杨友朋
 * @Date 2023/6/19 15:56
 **/
@RestController
@CrossOrigin
@RequestMapping("/teacher")
public class TeacherController {
    @Resource
    TeacherService teacherService;

    /**
    * @Author 杨友朋
    * @Description TODO 分页全查教师信息
    * @Date 2023/6/21 20:34
    * @Return CommonResult
    * @param teacher，pageRequest
    */
    @GetMapping("/selectTeacher")
    public CommonResult selectTeacher(Teacher teacher, PageRequest pageRequest){
        return CommonResult.ok(teacherService.selectTeacher(teacher,pageRequest));
    }

    /**
    * @Author 杨友朋
    * @Description TODO 全查教师
    * @Date 2023/6/26 9:34
    * @Return CommonResult
    * @param teacher
    */
    @GetMapping("/selectAll")
    public CommonResult selectAll(Teacher teacher){
        return CommonResult.ok(teacherService.selectAll(teacher));
    }
    /**
    * @Author 杨友朋
    * @Description TODO 添加教师信息
    * @Date 2023/6/21 20:34
    * @Return CommonResult
    * @param teacher
    */
    @PostMapping("/insertTeacher")
    public CommonResult insertTeacher(MultipartFile file, Teacher teacher, ImageFile imageFile) {
        return teacherService.insertTeacher(file,teacher,imageFile);
    }


    /**
    * @Author 杨友朋
    * @Description TODO 根据id删除教师信息
    * @Date 2023/6/21 20:35
    * @Return CommonResult
    * @param id
    */
    @GetMapping("/deleteTeacherById")
    public CommonResult deleteTeacherById(Integer id) {
        return teacherService.deleteTeacherById(id);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据ids批量删除教师信息
    * @Date 2023/6/21 20:36
    * @Return CommonResult
    * @param ids
    */
    @PostMapping("/deleteTeacherByIds")
    public CommonResult deleteTeacherByIds(@RequestBody List<Integer> ids) {
        return teacherService.deleteTeacherByIds(ids);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 根据id修改教师信息
    * @Date 2023/6/21 20:36
    * @Return CommonResult
    * @param teacher
    */
    @PostMapping("/updateTeacher")
    public CommonResult updateTeacher(@RequestBody Teacher teacher) {
        return teacherService.updateTeacher(teacher);
    }
}
